let prepare = document.getElementById("prepare")
let text = document.getElementById("text")
let pass = document.getElementById("pass")
let add = document.getElementById("add")
let i = 0
let k = 0
let toDo = new Array()
let toDo2 = new Array()
add.onclick = function () {
    if (text.value != "") {
        let content = text.value
        toDo[i] = "item" + i
        localStorage.setItem(toDo[i], content)
        localStorage.setItem("toDoLength", toDo.length)
        i++
        let container = document.createElement("div")
        let item = document.createElement("input")
        let add = document.createElement("span")
        let del = document.createElement("span")
        add.classList.add("iconfont", "icon-xieru", "add2")
        del.classList.add("iconfont", "icon-icon-resv-cancel-nor")
        add.onclick = function () {
            toDo2[k] = "item2" + k
            pass.appendChild(this.parentElement)
            localStorage.setItem(toDo2[k], this.parentElement.value)
        }
        del.onclick = function () {
            this.parentElement.remove()
        }
        item.value = content
        container.appendChild(item)
        container.appendChild(add)
        container.appendChild(del)
        prepare.append(container)


    }


}
// 存储功能
window.onload = function () {
    for (let i = 0; i < eval(localStorage.getItem("toDoLength")); i++) {
        let container = document.createElement("div")
        let item = document.createElement("input")
        let add = document.createElement("span")
        let del = document.createElement("span")
        add.classList.add("iconfont", "icon-xieru", "add2")
        del.classList.add("iconfont", "icon-icon-resv-cancel-nor")
        add.onclick = function () {
            pass.appendChild(this.parentElement)
        }
        del.onclick = function () {
            this.parentElement.remove()
        }
        item.value = localStorage.getItem("item" + i)
        container.appendChild(item)
        container.appendChild(add)
        container.appendChild(del)
        prepare.append(container)
        console.log(localStorage.getItem(toDo[i]))
    }
}







